<template>
  <div class="box">
    <el-carousel :interval="5000" height="400px">
      <el-carousel-item>
        <img src="@/assets/images/1.jpg" alt="">
      </el-carousel-item>
      <el-carousel-item>
        <img src="@/assets/images/2.jpg" alt="">
      </el-carousel-item>
      <el-carousel-item>
        <img src="@/assets/images/3.jpg" alt="">
      </el-carousel-item>
      <el-carousel-item>
        <img src="@/assets/images/4.jpg" alt="">
      </el-carousel-item>
    </el-carousel>
    <div class="bottom">
      <h2>热门学习资源</h2>
      <div class="card">
        <a target="_blank" :href="item.moocLink" class="card_box" v-for="item,index in list" :class="id===item.courseId ? 'active':''" :key="item.courseId" @mouseleave="mouseleave()" @mouseover="mouseoverFn(item.courseId)">
          <div class="img"><img :src="item.courseImg" alt=""></div>
          <div class="text text-ellipsis">{{item.coursename}}</div>
        </a>
      </div>
      <h2 class="more" @click="$router.push('/GoodQualityourse')">更多 <i class="el-icon-bottom"></i></h2>
    </div>
  </div>
</template>
<script>
import { getCourseList } from '@/api/course'
export default {
  data() {
    return {
      pagination: {
        total: 0,
        size: 10,
        current: 1
      },
      list: [],
      id: ''
    }
  },
  mounted() {
    const data = {
      course: {},
      page: this.pagination,
      sort: 0
    }
    getCourseList(data).then(res => {
      this.list = res.data.records
    })
  },
  methods: {
    mouseoverFn(id) {
      this.id = id
    },
    mouseleave() {
      this.id = ''
    }
  }
}
</script>

<style lang="less" scoped>
.more {
  color: #347abb;
  cursor: pointer;
}
.merry-go-round {
  height: 500px;
}
.el-carousel__item h3 {
  color: #475669;
  font-size: 18px;
  opacity: 0.75;
  line-height: 300px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
img {
  width: 100%;
  height: 100%;
}
.bottom {
  padding-bottom: 10px;
  h2 {
    width: 100%;
    text-align: center;
  }
  .card {
    cursor: pointer;
    display: flex;
    flex-wrap: wrap;
    gap: 17.5px;
    .card_box {
      position: relative;
      transition: all 0.1s ease;
      top: 0px;
      width: 226px;
      overflow: hidden;
      background-color: #fff;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
      border-radius: 5px;
      .text {
        font-size: 18px;
        font-weight: 700;
        width: 100%;
        text-align: center;
        margin: 16px 0;
      }
    }
  }
  .active {
    top: -10px !important;
  }
}
.text-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 1;
  display: -webkit-box;
  -webkit-box-orient: vertical;
}
</style>